import axios from '@/utils/request'
const base = '/movieserver'

export function listMovie(params) {
  return axios({
    url: `${base}/movieInstances`,
    method: 'get',
    params: params
  })
}

export function downloadMovieCover(id, version) {
  return axios.get(`${base}/movieInstances/movie/${id}/v/${version}/cover`, { responseType: 'arraybuffer', timeout: 3600000 })
}

export function movieDetails(id, version) {
  return axios({
    url: `${base}/movieInstances/movie/${id}/v/${version}`,
    method: 'get'
  })
}

export function online(id) {
  return axios({
    url: `${base}/movies/` + id + '/online',
    method: 'put'
  })
}

export function offline(id) {
  return axios({
    url: `${base}/movies/` + id + '/offline',
    method: 'put'
  })
}

export function setPrice(id, data) {
  return axios({
    url: `${base}/movies/` + id + '/price',
    method: 'put',
    data
  })
}

export function setLevel(id, movieLevelId) {
  return axios({
    url: `${base}/movies/` + id + '/level/' + movieLevelId,
    method: 'put'
  })
}

export function movieVersions(params) {
  return axios({
    url: `${base}/movieInstances/versions`,
    method: 'get',
    params: params
  })
}

export function deleteMovieFiles(movieInstanceId) {
  return axios({
    url: `${base}/movieInstances/${movieInstanceId}/files`,
    method: 'delete'
  })
}

export function deleteMovieInstance(movieInstanceId) {
  return axios({
    url: `${base}/movieInstances/${movieInstanceId}`,
    method: 'delete'
  })
}
